// =============================================================================
//  Spangles Analyzer
//
//  Copyright(c) 2008
//  See LICENSE.txt for licensing information.
// =============================================================================

package com.google.spangles.interfaces.impl;

import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Set;

import com.google.spangles.domain.Location;
import com.google.spangles.interfaces.Bounded;

/**
 * (Description)
 * (Any invariants [conditions that are always true] )
 * (Usage instructions, and/or examples)
 * (TODOs, ASSUMPTIONs, etc.)
 * (Known Bugs)
 * (Concurrency strategy - not thread safe or how it's thread safe)
 * 
 * @author Chris
 */
public abstract class AbstractBounded implements Bounded
{
   class ByX implements Comparator<Location>
   {
      public int compare(Location o1, Location o2)
      {
         return o1.getX()-o2.getX();
      }      
   }
   
   class ByY implements Comparator<Location>
   {
      public int compare(Location o1, Location o2)
      {
         return o1.getY()-o2.getY();
      }      
   }
   
   public abstract Collection<Location> locations();

   /**
    * (Description - what the method does and why)
    * (Visibility decision, if not obvious)
    * (Pre/Post Conditions)
    * (Usage examples)
    * (Algorithmic notes)
    * (Concurrency issues)
    * @return
    */
   public int getMinimumX()
   {
      Collection<Location> s = locations();
      return Collections.min(s, new ByX()).getX();
   }

   public int getMaximumX()
   {
      Collection<Location> s = locations();
      return Collections.max(s, new ByX()).getX();
   }
   
   /**
    * (Description - what the method does and why)
    * (Visibility decision, if not obvious)
    * (Pre/Post Conditions)
    * (Usage examples)
    * (Algorithmic notes)
    * (Concurrency issues)
    * @return
    */
   public int getMinimumY()
   {
      Collection<Location> s = locations();
      return Collections.min(s, new ByY()).getY();
   }

   public int getMaximumY()
   {
      Collection<Location> s = locations();
      return Collections.max(s, new ByY()).getY();
   }
}
